home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / cdrecord / defaults.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-02  |  3.5 KB  |  172 lines

  1. /* @(#)defaults.c    1.5 00/06/02 Copyright 1998 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)defaults.c    1.5 00/06/02 Copyright 1998 J. Schilling";
  5. #endif
  6. /*
  7.  *    Copyright (c) 1998 J. Schilling
  8.  */
  9. /*
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2, or (at your option)
  13.  * any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; see the file COPYING.  If not, write to
  22.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #include <mconfig.h>
  26. #include <stdxlib.h>
  27. #include <strdefs.h>
  28. #include <stdio.h>
  29. #include <standard.h>
  30. #include <deflts.h>
  31. #include <utypes.h>
  32. #include <schily.h>
  33. #include "cdrecord.h"
  34.  
  35. EXPORT    void    cdr_defaults    __PR((char **devp, int *speedp, long *fsp));
  36. LOCAL    void    cdr_xdefaults    __PR((char **devp, int *speedp, long *fsp));
  37. LOCAL    char *    strsv        __PR((char* s));
  38.  
  39. EXPORT void
  40. cdr_defaults(devp, speedp, fsp)
  41.     char    **devp;
  42.     int    *speedp;
  43.     long    *fsp;
  44. {
  45.     char    *dev    = *devp;
  46.     int    speed    = *speedp;
  47.     long    fs    = *fsp;
  48.  
  49.     if (!dev) {
  50.         *devp = getenv("CDR_DEVICE");
  51.  
  52.         if (!*devp && defltopen("/etc/default/cdrecord") == 0) {
  53.             dev = defltread("CDR_DEVICE=");
  54.             if (dev != NULL)
  55.                 *devp = strsv(dev);
  56.         }
  57.     }
  58.     if (*devp)
  59.         cdr_xdefaults(devp, &speed, &fs);
  60.  
  61.     if (speed < 0) {
  62.         char    *p = getenv("CDR_SPEED");
  63.  
  64.         if (!p) {
  65.             if (defltopen("/etc/default/cdrecord") == 0) {
  66.                 p = defltread("CDR_SPEED=");
  67.             }
  68.         }
  69.         if (p) {
  70.             speed = atoi(p);
  71.             if (speed < 0)
  72.                 comerrno(EX_BAD, "Bad speed environment.\n");
  73.         }
  74.     }
  75.     if (speed >= 0)
  76.         *speedp = speed;
  77.  
  78.     if (fs < 0L) {
  79.         char    *p = getenv("CDR_FIFOSIZE");
  80.  
  81.         if (!p) {
  82.             if (defltopen("/etc/default/cdrecord") == 0) {
  83.                 p = defltread("CDR_FIFOSIZE=");
  84.             }
  85.         }
  86.         if (p) {
  87.             if (getnum(p, &fs) != 1)
  88.                 comerrno(EX_BAD, "Bad fifo size environment.\n");
  89.         }
  90.     }
  91.     if (fs > 0L)
  92.         *fsp = fs;
  93.  
  94.     defltclose();
  95. }
  96.  
  97. LOCAL void
  98. cdr_xdefaults(devp, speedp, fsp)
  99.     char    **devp;
  100.     int    *speedp;
  101.     long    *fsp;
  102. {
  103.     char    dname[256];
  104.     char    *p = *devp;
  105.     char    *x = ",:/@";
  106.  
  107.     while (*x) {
  108.         if (strchr(p, *x))
  109.             return;
  110.         x++;
  111.     }
  112.     js_snprintf(dname, sizeof(dname), "%s=", p);
  113.     if (defltopen("/etc/default/cdrecord") != 0)
  114.         return;
  115.  
  116.     p = defltread(dname);
  117.     if (p != NULL) {
  118.         while (*p == '\t')
  119.             p++;
  120.         if ((x = strchr(p, '\t')) != NULL)
  121.             *x = '\0';
  122.         *devp = strsv(p);
  123.         if (x) {
  124.             p = ++x;
  125.             while (*p == '\t')
  126.                 p++;
  127.             if ((x = strchr(p, '\t')) != NULL)
  128.                 *x = '\0';
  129.             if (*speedp < 0)
  130.                 *speedp = atoi(p);
  131.         }
  132.         if (x) {
  133.             p = ++x;
  134.             while (*p == '\t')
  135.                 p++;
  136.             if ((x = strchr(p, '\t')) != NULL)
  137.                 *x = '\0';
  138.             if (*fsp < 0L) {
  139.                 if (getnum(p, fsp) != 1)
  140.                     comerrno(EX_BAD,
  141.                     "Bad fifo size in defaults.\n");
  142.             }
  143.         }
  144.         if (x) {
  145.             p = ++x;
  146.             while (*p == '\t')
  147.                 p++;
  148.             if ((x = strchr(p, '\t')) != NULL)
  149.                 *x = '\0';
  150.             if (strcmp(p, "\"\"")) {
  151.                 extern    char    *driveropts;
  152.  
  153.                 if (driveropts == NULL)
  154.                     driveropts = strsv(p);
  155.             }
  156.         }
  157.     }
  158. }
  159.  
  160. LOCAL char *
  161. strsv(s)
  162.     char    *s;
  163. {
  164.     char    *p;
  165.     int len = strlen(s);
  166.  
  167.     p = malloc(len+1);
  168.     if (p)
  169.         strcpy(p, s);
  170.     return (p);
  171. }
  172.